package NetModel.okhttp.requset;

import android.support.annotation.NonNull;


import java.util.Map;

import NetModel.okhttp.OkHttpClientManger;
import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2016/10/27.
 */
public class PostRequestBuilder extends BaseRequest<PostRequestBuilder> {


    @Override
    public Call build() {
        Request req = new Request.Builder()
                .url(url)
                .headers(addHead(heads))
                .post(addParams(params))
                .tag(tag)
                .build();
        Call call = OkHttpClientManger.getInstance().getClient().newCall(req);
        return call;
    }

    private RequestBody addParams(@NonNull Map<String, String> params) {
        FormBody.Builder bodyBuilder = new FormBody.Builder();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            bodyBuilder.add(entry.getKey(), entry.getValue());
        }
        return bodyBuilder.build();
    }

}
